#include "common.h"
#include "camera.h"

using namespace cg;
using namespace std;

Camera::Camera()
{
	eye.Set( 0.0f, 0.0f, 1.5f );
	up.Set( 0.0f, 1.0f, 0.0f );
	target.Set( 0.0f, 0.0f, 0.0f );
	UpdateDir();
	UpdateRight();
}

void Camera::Work() const
{		
	gluLookAt( eye.x, eye.y, eye.z,
			   target.x, target.y, target.z,
			   up.x, up.y, up.z );
	
}

void Camera::Yaw( float step )
{		
	target = eye + ( RotationMatrix( step, up ) * toVec4( dir ) ).toVec3();	
	//
	UpdateDir();	
	UpdateRight();
}

void Camera::Pitch( float step )
{		
	Vec3 temp = ( RotationMatrix( step, right ) * toVec4( dir ) ).toVec3();		
	if ( abs( temp.DotProduct( up ) ) < 0.8f ) {
		target = eye + temp;
		UpdateDir();	
		UpdateRight();
	}
}